<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="车牌号" prop="carNum">
        <el-input
          v-model="queryParams.carNum"
          placeholder="请输入车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据时间">
        <el-date-picker
          v-model="daterangeDataTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:carOil:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="carOilList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="index" label="序号" width="60" align="left" />
        <el-table-column
        label="所属部门单位"
        align="left"
        prop="deptName"
        minWidth="120px"
      />
     
      <el-table-column
        label="车牌号"
        align="left"
        prop="carNum"
        minWidth="100px"
      />
      <el-table-column
        label="数据时间"
        align="left"
        prop="dataTime"
        width="180"
      />

      <el-table-column label="当前油量" align="left" prop="carOil" />
      <el-table-column label="油量变化" align="left" prop="oilChanged" />
      <el-table-column label="平均油量消耗" align="left" prop="oilMean" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listCarOil,
  getCarOil,
  delCarOil,
  addCarOil,
  updateCarOil,
} from "@/api/report/carOil";

export default {
  name: "CarOil",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆油量统计表格数据
      carOilList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 平均油量消耗时间范围
      daterangeDataTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataTime: undefined,
        carNum:undefined,
        deptId:undefined,
      },
    
    };
  },
    computed: {
    deptId() {
      return this.$store.getters.choosedDeptId;
    },
  },
  watch: {
    deptId: function () {
      this.queryParams.deptId = this.deptId;

      this.getList();
    },
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车辆油量统计列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDataTime && "" != this.daterangeDataTime) {
        this.queryParams.params["beginDataTime"] = this.daterangeDataTime[0];
        this.queryParams.params["endDataTime"] = this.daterangeDataTime[1];
      }
      listCarOil(this.queryParams).then((response) => {
        this.carOilList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
   
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDataTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.oilId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  
    /** 删除按钮操作 */
    handleDelete(row) {
      const oilIds = row.oilId || this.ids;
      this.$modal
        .confirm('是否确认删除"' + (row.orderName || "已勾选") + '"的数据项?')
        .then(() => {
          this.loading = true;
          return delCarOil(oilIds);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "report/carOil/export",
        {
          ...this.queryParams,
        },
        `车辆油量统计_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
